package com.tql.mall.user.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tql.mall.model.customer.Customer;
import com.tql.mall.model.customer.CustomerAddr;
import com.tql.mall.model.merchant.Merchant;
import com.tql.mall.model.merchant.MerchantLoginDto;
import com.tql.mall.model.merchant.MerchantLoginVo;
import com.tql.mall.user.service.CustomerAddrService;
import com.tql.mall.user.service.CustomerService;
import com.tql.mall.user.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "第三方服务调用接口")
@RestController
@RequestMapping("/user/api")
public class UserApiController {

    @Autowired
    private CustomerAddrService customerAddrService;

    @Autowired
    private CustomerService customerService;

    @Autowired
    private MerchantService merchantService;

    @ApiOperation("商家登录")
    @GetMapping("/login")
    public Merchant login(@RequestBody MerchantLoginVo merchantLoginVo) {
        MerchantLoginDto merchantLoginDto = merchantService.login(merchantLoginVo);
        return merchantLoginDto.getMerchant();
    }


    @ApiOperation("根据顾客ID获取顾客地址列表")
    @GetMapping("/inner/getCustomerAddrList/{customerId}")
    public List<CustomerAddr> getCustomerAddrList(@PathVariable Long customerId) {
        return customerAddrService.list(new QueryWrapper<CustomerAddr>().eq("user_id", customerId));
    }

    @ApiOperation("根据顾客ID获取顾客信息")
    @GetMapping("/inner/getCustomer/{customerId}")
    public Customer getCustomer(@PathVariable Long customerId) {
        return customerService.getById(customerId);
    }

}
